<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    //优化前
    function add(a, b) {
        b = b || 1; // 避免b的值未传入
        return a + b;
    }

    console.log('优化前的结果:' + add(10));

    //1、 优化后
    function add2(a, b = 5) {
        return a + b;
    }

    console.log('优化后的结果:' + add2(10));

    // 2、不定参数
    function fun(...values) {
        console.log('参数的长度为:' + values.length);
    }

    fun(1, 2);
    fun(1, 2, 3, 4, 5);

    // /箭头函数
    var print = obj => console.log(obj);
    print('华为');

    var sum = (a, b) => a + b;
    console.log('箭头函数sum:' + sum(20, 30));

    var sum2 = (a, b) => {
        c = a + b;
        return a + c;
    };
    console.log('箭头函数sum2:' + sum2(10, 20));
</script>

<script>
    /*箭头函数 + 结构表达式*/
    const person = {
        name: "jack",
        age: 21,
        language: ['java', 'c++', 'python', 'go', 'kotlin']
    }

    function hello(person) {
        console.log("hello", +person.name);
    }

    var hello2 = ({name}) => console.log("hello," + name);
    hello2(person);

    var study = ({language}) => console.log("我学习过的语言有" + language);
    study(person);
</script>
</body>
</html>